<template>
  <div class="not-found-container">
    <div class="not-found-content">
      <el-result
        icon="error"
        title="404"
        sub-title="抱歉，您访问的页面不存在"
      >
        <template #extra>
          <el-button type="primary" @click="goHome">返回首页</el-button>
          <el-button @click="goBack">返回上一页</el-button>
        </template>
      </el-result>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { onMounted } from 'vue'

const router = useRouter()
const userStore = useUserStore()

const goHome = () => {
  // 如果已登录，跳转到首页；否则跳转到登录页
  console.log('isLoggedIn:', userStore.isLoggedIn) 
  console.log('id:', userStore.id)
  
  if (userStore.isLoggedIn) {
    router.push('/dashboard')
  } else {
    router.push('/login')
  }
}

const goBack = () => {
  router.go(-1)
}

onMounted(() => {
  console.log('userStore.id:', userStore.id)
  console.log('isLoggedIn:', userStore.isLoggedIn)
  console.log('localStorage user_id:', localStorage.getItem('user_id'))
})
</script>

<style scoped>
.not-found-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f7fa;
}

.not-found-content {
  background-color: #fff;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  text-align: center;
}
</style> 